home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / mathstud.zip / FILTER.M < prev    next >
Text File  |  1993-09-15  |  705b  |  43 lines

  1. function [y, zf] = filter(b, a, x, z)
  2. % [y, zf] = filter(b, a, x, z)
  3. % computes the output of a digital filter (a wrapper around the
  4. % built-in _filter)
  5.  
  6. %       S.Halevy 7/31/92
  7. %       Copyright (c) 1992 by the MathWizards
  8.  
  9. % error checking
  10.  
  11. if nargin < 3
  12.    error('filter: not enough input arguments');
  13. end
  14.  
  15. x=x(:)';
  16. a=a(:)';
  17. b=b(:)';
  18.  
  19. na = length(a);
  20. if na == 1
  21.    a=[a 0];
  22. end
  23. na = length(a);
  24. nb = length(b);
  25. nz = max(na,nb);
  26.   
  27. if nargin < 4
  28.    z = zeros(1,nz);
  29. else
  30.    z=z(:)';
  31. end
  32.  
  33. if length(z) ~= nz
  34.    error('filter state must match coefficients');
  35. end
  36.  
  37. if abs(a(1))==0
  38.    error('first element of A can not be zero')
  39. end
  40.  
  41. [y, zf]= _filter(x, a, b, z);
  42.  
  43.